package com.lam.framework.datasource.model;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import com.lam.common.utils.StringUtils;
import com.lam.framework.datasource.JdbcContextHolder;
import com.lam.framework.datasource.constant.BaseDsType;

/**
 * @author lam
 *
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

//	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Override
	protected Object determineCurrentLookupKey() {
		String key = JdbcContextHolder.getDataSource();
		if(StringUtils.isBlank(key)){
			key = BaseDsType.MASTER;
		}
		//log.debug("当前数据源为: {}", key);
		return key;
	}
	
}